package com.xxx;

import java.io.DataInputStream;

import java.io.InputStream;

import java.net.ServerSocket;
import java.net.Socket;

public class ServerA extends Thread{


    @Override
    public void run() {

        System.out.println("服务器A启动");

        while (true) {
            try {
                ServerSocket serverA = new ServerSocket(6666);

                Socket accept = serverA.accept();

                InputStream is = accept.getInputStream();
                DataInputStream dis = new DataInputStream(is);
                System.out.println(accept.getRemoteSocketAddress()+ "上线了");
                System.out.println(accept.getPort());
                while (true) {
                    try {
                        String s = dis.readUTF();
                        System.out.println(s);
                    } catch (Exception e) {
                        System.out.println(accept.getRemoteSocketAddress() + "离线了");
                        serverA.close();
                        break;
                    }

                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }


    }
}
